Invoking a Web Service using an HTTP Request
APA-2110
This section describes how to invoke a Web service using an HTTP request. It also describes how to configure a proxy server.
Do not use the Web Reference object as this feature is deprecated and will be removed in future versions.
Currency Name Web Service Overview
This topic describes a sample project implementation that utilizes a public Currency Name Web service, and demonstrates how to call the GetCurrencyName function to return the currency of a country. The same methodology can be applied to other Web service functions.
The source files for this project can be found at: https://www.extranice.com/EIS/AdditionalResources/RTSAR/Forms/AllItems.aspx
The Currency Name Web service and the GetCurrencyName function are described in:
http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?op=CurrencyName
The GetCurrencyName function uses the parameter sCurrencyISOCode.
The following is the SOAP request envelope used by the GetCurrencyName Web service function:
POST /websamples.countryinfo/CountryInfoService.wso HTTP/1.1
Host: webservices.oorsprong.org
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CurrencyName xmlns="http://www.oorsprong.org/websamples.countryinfo">
<sCurrencyISOCode>string</sCurrencyISOCode>
</CurrencyName>
</soap:Body>
</soap:Envelope>
The following is the SOAP response envelope returned by this function:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CurrencyNameResponse xmlns="http://www.oorsprong.org/websamples.countryinfo">
<CurrencyNameResult>string</CurrencyNameResult>
</CurrencyNameResponse>
</soap:Body>
</soap:Envelope>
Creating the Basic HTTP Request Business Entities
You need to create the basic business entities, including an HTTP Request base type and a parameter (sCurrencyISOCode) required by the GetCurrencyName function of the Currency Name Web service.
To create the HTTP request business entities:
1. | Create a new type called Demo WebService with Base type set to Http Request (from Library Types > Communication).. |
2. | Create an instance of Demo WebService and rename it Demo. |
3. | Add CurrencyCode as a Text, and set the Initial Value to USD. |
4. | Expand Demo and select Content Type. Then set the Initial value to text/xml; charset=utf-8. |
5. | Select Request Method and set the Initial value to POST. |
6. | Select Url and set the Initial value to http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?op=CurrencyName. |
Creating the HTTP Request Function
To invoke the Web service, create a GetCurrencyName function. This function builds the SOAP request by concatenating various text strings in the form:
Header (including the Web service function opening tag) + <Parameter1> + Parameter1 + </Parameter1> + <Parameter2> + Parameter2 + </Parameter2> + Footer (starting with the Web service function closing tag)
Although this example only uses two parameters, this can be generalized for more parameters in a similar form.
The GetCurrencyName function includes the following instructions:
1. | Assigns an empty string to the Response property. |
2. | Prepares the SOAP request by concatenating the following items and assigns them to the Request Body: |
The start of the request: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><CurrencyName xmlns="http://www.oorsprong.org/websamples.countryinfo">
The sCurrencyISOCode opening tag: <sCurrencyISOCode>
The Currency Code parameter: CurrencyCode
The sCurrencyISOCode closing tag: </sCurrencyISOCode>
The CurrencyName closing tag: </CurrencyName>
The soap body closing tag: </soap:Body>
The end of the request: </soap:Envelope>
3. | Posts the Request to the Web server for the Currency Name Web service. The Post Request method is called (you can also call the Post Request Asynchronous version). When completed, this populates the XML Response property. |
To create the HTTP request function:
1. | In the Types tab, under DemoWebservice, add a GetCurrencyName function. |
2. | Insert the following function instructions: |
Assign into Xml Response
Assign Concatenate [<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><CurrencyName xmlns="http://www.oorsprong.org/websamples.countryinfo"><CurrencyISOCode> CurrencyCode </sCurrencyISOCode> </CurrencyName></soap:Body></soap:Envelope>] into Request Body
Post request to a web server of DemoWebservice
Now that you have the data, you can use Text functions (such as Find Subtext Position or Extract Subtext) or XML library types to get the values (for example, find the position of <attribute> and </attribute> and then extract the value based on these positions).
Creating the HTTP Request Event Handler
You need to create an event handler that runs the InvokeWebMethod when the Boolean value is modified.
To create the HTTP request event handler:
1. | In the Business Logic > Event Handler tab, create a New Event Handler. |
2. | From the When the following event is raised drop-down list, select The value of Boolean is modified. |
3. | Insert an instruction GetCurrencyName of Demo. |
Testing the HTTP Request Project
You need to compile the project and run Monitor to test the project.
To test the HTTP request project:
1. | Ensure that the Real-Time Client process (RTClient.exe) is not running. |
2. | Click Generate Main Projectto compile the project. |
3. | Ensure that the project compiles without errors. |
4. | Click Run Main Project. The application runs. |
5. | Click Monitor. |
6. | Change the Boolean value. The Response appears in the Demo business entity (this is the same response if you invoke it from the browser). |
7. | Click to expand the Response. |
Configuring a Web Service Proxy
You can manually configure a Web service proxy (WSP) on the Real-Time Server.
To manually configure a Web service proxy:
1. | Back up <InstallationFolder>/Apache/conf/extra/wsp.rts.conf to <InstallationFolder>/Apache/conf/extra/wsp.rts.bak. |
This file is also generated by the Real-Time Server during the successful import of a WSDL. If you import WSDL files, you must modify this file again after the import.
2. | Open the <InstallationFolder>/Apache/conf/extra/wsp.rts.conf file for editing. |
3. | Override the content of the file with a new proxy request, for example: |
Listen 18183
NameVirtualHost *:18183
<VirtualHost *:18183>
ProxyRequests off
ProxyPass /WSP/CountryInformationService http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?op=CurrencyName
ProxyPass /WSP/Internal_URI1 External_URL1
</VirtualHost>
Each ProxyPass line represents a Web service. The /WSP/Internal_URI1 is the new URL that the client uses and the External_URL1 is the actual URL of the Web service.
4. | If the RT Server uses a proxy server, add an additional line after the ProxyRequests off line (where 87.249.122.80:8080 is the proxy IP address): |
ProxyRemote * http://87.249.122.80:8080
5. | Save the file. |
6. | Restart the RTServer Apache service. |
Using the Get Response Header Value
In version 7.1, the Get Response Header Value function was added.
Function / Event |
Return Value / Parameter |
Description |
Syntax |
Get Response Header Value |
Text |
Returns the value of the specified header key of a response. HTTP headers allow the client and the server to pass additional information with the request or the response. Few common http response headers are, Accept, Connection, and Date. For details. refer to: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields |
Get Value of the of Http Request <Header> of the response |